<?php // no direct access
defined('_JEXEC') or die('Restricted access'); 
//var_dump('default tpl');
?>
<div style="clear:both"></div>
<style>
.calendar_table{
	width:700px;
	border-top-style:solid;
	border-bottom-style:solid;
	border-right-style:solid;
	border-left-style:solid;
	border-width:1px;
	border-color:#333333;
	margin: 2px 0px 0px 0px;
}
.calendar_row{
	
	width:700px;
	height:150px;
}

h1.cal_nav{
	margin: -2px 0px 0px 0px;
}

#cal_nav_month{
	font-family:Arial, Helvetica, sans-serif;
	font-size:14px;
	font-weight: bold;
}
a.cal_nav{
	font-family:Arial, Helvetica, sans-serif;
	font-size:10px;
	font-weight: normal;
}

.cal_text_day{
	background-color:#FFFFFF;
	width:98px;
	height:14px;
	float:left;
	text-align:center;
	
	border-right-style:solid;
	border-left-style:solid;
	border-bottom-style:solid;
	border-top-style:solid;
	border-width:1px;
	border-color:#333333;
	font-family:Arial, Helvetica, sans-serif;
	font-size:12px;
}

.calendar_day{
	background-color:#FFFFFF;
	width:98px;
	height:150px;
	float:left;
	border-right-style:solid;
	border-left-style:solid;
	border-bottom-style:solid;
	border-top-style:solid;
	border-width:1px;
	border-color:#333333;
	overflow:hidden;
}
.calendar_day2{
	background-color: #00FFFF;
	width:98px;
	height:150px;
	float:left;
	border-right-style:solid;
	border-left-style:solid;
	border-bottom-style:solid;
	border-top-style:solid;
	border-width:1px;
	border-color:#333333;
	overflow:hidden;
}
.date{
	width:96px;
	height:12px;
	margin: 0px 5px 0px 0px;
	text-align:right;
	font-family:Arial, Helvetica, sans-serif;
	font-size:11px;

}
.event{	
	width:96px;
	margin: 0px 0px 0px 0px;
	text-align:right;
	font-family:Arial, Helvetica, sans-serif;
	font-size:9px;

}

</style>
<style type="text/css">

.spiffyfg{
 /* background:#EB7405;*/
  width:77px;
  margin: 0px 0px 0px px;
  padding:0px 0px 0px 4px;
  /*margin: 0px 5px 5px 5px;*/
  text-align:left;
	font-family:Arial, Helvetica, sans-serif;
	font-size:9px;
  }
</style>

<script type="text/javascript">

		window.addEvent('domready', function() {

			SqueezeBox.initialize({}); 

			$$('a.modal').each(function(el) {
				el.addEvent('click', function(e) {
					new Event(e).stop();
					SqueezeBox.fromElement(el);
				});
			});
		});
  </script>
<?php
	//var_dump($this->daysInMonth);
	$purl	= 'index.php?option=com_calendar&view=calendar&task=show&'.html_entity_decode( $this->cal_uri->prev('month') );
	//var_dump('purl');
	$text = 'prev';
	$attribs['class']	= 'cal_nav';
	$plink = JHTML::_('link', JRoute::_($purl), $text, $attribs);
	//var_dump('links');
	$nurl	= 'index.php?option=com_calendar&view=calendar&task=show&'.html_entity_decode( $this->cal_uri->next('month') );
	$text = 'next';
	$attribs['class']	= 'cal_nav';
	$nlink = JHTML::_('link', JRoute::_($nurl), $text, $attribs);
?>
<h1 id="cal_nav_month" class="cal_nav">	
	<?php echo $this->cal_text->thisMonthName();
		echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$plink.'&nbsp;&nbsp;&nbsp;'.$nlink;
	?>
</h1>
<div class="calendar_table" style="float:left">

<div>
<?php
//iterate through weekday names
$day_names = $this->cal_text->weekdayNames('short');
foreach($day_names as $name){
	echo '<div class="cal_text_day" >'.$name.'</div>';
}
?>
</div>
<?php
//var_dump('pre-calendar draw');
foreach($this->daysInMonth as $Day) {
			
			if ($Day->isFirst()) {
				
				$html .=  '<div class="calendar_row">'."\n";
			}
		
			if ($Day->isEmpty()) {
			// it's empty because where on a day that's not in this month:
			//   figure out which day of previous month and show it?
				$html .= '<div class="calendar_day2">&nbsp;</div>'."\n";
			} else {
				$test = method_exists( $Day  , 'isSelected');
				//echo $test;
				
				if($Day->isSelected()){ //->isSelected()
					//event date
					$html .='<div class="calendar_day" >'."\n\t".'<p class="date">'.$Day->thisDay()."</p>";
					
					while( $e = $Day->getEntry() ){
						//var_dump($e);
						//event title
						$html .= "\n\t".'<div class="event">';
						//make event link
						//////////////////////////////////
						// determine if calendar extension info is available; alter iframe height accordingly
						//var_dump($e->params);
						$params = new JParameter( $e->params );
						$assoc_isbn = $params->get('assoc_isbn', NULL);
						$assoc_gallery = $params->get('assoc_gallery', NULL);
						$h = 200;
						if($assoc_isbn){
							$h = $h + 100;
						}
						if($assoc_gallery){
							$h = $h + 120;
						}
						//////////////////////////////////
						//quick, make sure the event entry isn't lame(with artifically long titles by way of hyphenation)
						$e->title = preg_replace('/(-)([0-9a-zA-Z])/','\1 \2',$e->title);
						$url	= 'index.php?option=com_calendar&view=detail&task=view&tmpl=component&id='.$e->id;
						$status = "{handler: 'iframe', size: {x: 600, y: ".$h."}}";
						$text = '';
						$bg_img = 'components/com_calendar/images/bg'.$e->catid.'.png';
						$faux_img = 'components/com_calendar/images/bg34.png';
						 $text .= '<div style="width:auto;height:15px; z-index:100; background-image:url('
						 				."'"
										.$bg_img
										."'"
										.'); background-position: -4px 0px; background-repeat: no-repeat; margin: 0px 0px -1px 2px"></div>';
						 $text .= '<div style="width:auto;height:auto; z-index:200'
						 				
										.'; background-image:url('
						 				."'"
										.$bg_img
										."'"
										.');background-position: -4px -5px; background-repeat: no-repeat'
										
										.'; background-color: none'
										//.$e->cat_params->event_bg 		
										
										.'; margin: 0px 0px -18px 2px;position: relative; top: -10px">'
								.'<p class="spiffyfg" style="z-index:900; width:77px;height:auto; margin: 2px 0px 0px 0px;background-color: none;color:#'
								.$e->cat_params->event_fg
								.'; ">'
								. $e->title
								.'</p></div>'
								.'<div style="width:auto;height:15px; z-index:100; background-image:url('
						 				."'"
										.$bg_img
										."'"
										.'); background-position: -4px -60px; background-repeat: no-repeat;background-color: none;  margin: 0px 0px -5px 2px;"> </div>';
								 
						
						$attribs['class']	= JText::_( 'modal' );
						$attribs['rel'] = "".$status."";
						$link = JHTML::_('link', JRoute::_($url), $text, $attribs);
							
						$html .= $link;
						$html .= "</div>";
					}
					$html .= "</div>\n";
					
				}else{
					//no event, just date
					$html .='<div class="calendar_day" >'."\n\t".'<p class="date">'.$Day->thisDay()."</p></div>\n";;
				}//end selected
				
			}
		
			if ($Day->isLast()) {
				//end row
				$html .= "</div>\n";
			}
		}//edn foreach
		echo $html;
?>

</div>
<div style="clear:both;"></div>